﻿using GalaSoft.MvvmLight.Command;
using Siasun.AFC.RtPlatfromGui.IBll.IServer;
using Siasun.AFC.RtPlatfromGui.IBll.Model;
using Siasun.AFC.RtPlatfromGui.UI.BusinessHelper;
using Siasun.AFC.RtPlatfromGui.UI.Model;
using Siasun.AFC.RtPlatfromGui.UI.ViewModel.BaseViewModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace Siasun.AFC.RtPlatfromGui.UI.ViewModel
{
    public class PlatFromMenuPageViewModel : PageBaseViewModel
    {
        #region 字段
        private MenuInfo currentMenuInfo;
        private ObservableCollection<MenuTreeInfo> menuTreeList;
        #endregion

        #region 绑定属性
        /// <summary>
        /// 当前菜单项
        /// </summary>
        public MenuInfo CurrentMenuInfo
        {
            get
            {
                return currentMenuInfo;
            }

            set
            {
                currentMenuInfo = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 菜单树集合
        /// </summary>
        public ObservableCollection<MenuTreeInfo> MenuTreeList
        {
            get
            {
                return menuTreeList;
            }

            set
            {
                menuTreeList = value;
                RaisePropertyChanged();
            }
        }
        #endregion

        #region 命令
        /// <summary>
        /// 选中菜单触发的命令
        /// </summary>
        public RelayCommand<MenuTreeInfo> SelectedMenuCommand { get; set; }

        /// <summary>
        /// 双击菜单触发的命令
        /// </summary>
        public RelayCommand<MenuTreeInfo> DoubleMenuCommand { get; set; }
        #endregion

        #region 构造函数
        public PlatFromMenuPageViewModel()
        {
            #region Delete 测试数据
            //var createMenuList = new ObservableCollection<MenuTreeInfo>();
            //createMenuList.Add(new MenuTreeInfo {
            //    MenuName = "测试",
            //    IsCanUse = true,
            //    MenuTag = new MenuInfo() {
            //        MenuName = "测试"
            //    },
            //    ChildrenList = new ObservableCollection<MenuTreeInfo>{
            //         new MenuTreeInfo() {
            //         MenuName = "测试3",
            //         IsCanUse = true,
            //         MenuTag = new MenuInfo() {
            //            MenuName = "测试3"
            //            },
            //         }
            //    }
            //});
            //createMenuList.Add(new MenuTreeInfo {
            //    MenuName = "测试2",
            //    IsCanUse = false,
            //    MenuTag = new MenuInfo()
            //    {
            //        MenuName = "测试2"
            //    },
            //});
            //MenuTreeList = createMenuList; 
            #endregion

            SelectedMenuCommand = new RelayCommand<MenuTreeInfo>(t => SelectedMenu(t));
            DoubleMenuCommand = new RelayCommand<MenuTreeInfo>(t => DoubleMenu(t));
        }
        #endregion

        #region 方法
        public override void AsynStatusTimer_Tick(object sender, ElapsedEventArgs e)
        {
            //throw new NotImplementedException();
        }

        public override void InitConfig()
        {
            //获取根元素树
            MenuTreeList = MenuDataHelper.GetInstanse().GetMenuTreeForUse();
        }

        public override void InitLayout()
        {
            //throw new NotImplementedException();
        }

        public override void InitVoice()
        {
            //throw new NotImplementedException();
        }


        #endregion

        #region 事件
        public override void LoadPageInitLayout(object obj)
        {
            //初始化参数
            this.InitConfig();
            //初始化界面
            this.InitLayout();
            //发送语音
            InitVoice();
        }

        public override void UnLoadPageOper(object obj)
        {
            //throw new NotImplementedException();
        }

        public void SelectedMenu(MenuTreeInfo menuTreeInfo)
        {
            if (object.Equals(null, menuTreeInfo.MenuTag))
            {
                CurrentMenuInfo = new MenuInfo() { MenuName = "菜单信息获取失败" };
            }
            CurrentMenuInfo = menuTreeInfo.MenuTag;
        }

        public void DoubleMenu(MenuTreeInfo menuTreeInfo)
        {
            if (object.Equals(null, menuTreeInfo.MenuTag))
            {
                CurrentMenuInfo = new MenuInfo() { MenuName = "菜单信息获取失败" };
            }
            CurrentMenuInfo = menuTreeInfo.MenuTag;
            if (menuTreeInfo.ChildrenList.Count == 0)
            {
                //CurrentMenuInfo.MenuName = "菜单被双击";
            }
            CurrentMenuInfo = CurrentMenuInfo;
        } 
        #endregion
    }
}
